package handler

import (
	"github.com/starmotioncf/soutchatinternal/dto"
	"github.com/starmotioncf/soutchatinternal/errcode"
	"github.com/starmotioncf/soutchatinternal/resp"
	"github.com/starmotioncf/soutchatinternal/service"

	"github.com/gin-gonic/gin"
)

type SmsHandler struct {
	smsService service.SmsService
}

func NewSmsHandler(smsService service.SmsService) *SmsHandler {
	return &SmsHandler{
		smsService: smsService,
	}
}

// SendCaptcha 发送短信验证码
// @Tags 短信
// @Summary  发送短信验证码
// @Description 发送短信验证码
// @Accept json
// @param json body dto.SmsSendCaptchaReq true "请求数据"
// @Produce  json
// @Response 200 {object} resp.Resp{data=dto.SmsSendCaptchaRes}
// @Router /sms/captcha [post]
// @Security Bearer
func (h *SmsHandler) SendCaptcha(ctx *gin.Context) {
	var req dto.SmsSendCaptchaReq
	if err := ctx.BindJSON(&req); err != nil {
		resp.Error(ctx, errcode.ErrInvalidParams.Wrap(err))
		return
	}
	codeId, err := h.smsService.SendCaptcha(ctx, &req)
	if err != nil {
		resp.Error(ctx, err)
		return
	}
	resp.ReturnMustJson(ctx, dto.SmsSendCaptchaRes{CodeId: codeId}, err)
}
